from flask import Flask,request,make_response,session,sessions

app = Flask(__name__)
app.secret_key = 'low game'

@app.route('/log')
def create():
    ret = make_response('创建成功')
    ret.set_cookie('fight','10')
    ret.set_cookie('HP','10')
    return ret

@app.route('/layer/1')
def layer_1():
    session['layer'] = "2"
    ret_data = bytes('{"msg":msg,"new layer":"""碰见一个小兔子。'
    'A:攻击'
    'B：捕捉'
    'C:红烧'
    '"""}'.encode("utf-8"))
    return ret_data

@app.route('/layer/2')
def layer_2():
    if session.get('layer') != "2":
        return '你该去第二层闯关了'
    ret = make_response("创建角色成功")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "已击杀，掉落兔毛大衣，装备上血量加 20"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 20))
    elif q.lower() == "b":
        msg = "捕捉到一只萌宠，真可爱"
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 40))
    elif q.lower() == "c":
        msg = "红烧兔子肉 就是好吃"
        ret.set_cookie('fight', str(int(request.cookies.get('fight')) + 20))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""碰见一头大虫：'
                        'A:击杀他'
                        'B：捕捉'
                        'C: 打不过 快跑'
                     '"""}'.encode("utf-8")))
    session['layer'] = "3"
    return ret

@app.route('/layer/3')
def layer_3():
    session['layer'] = '3'
    ret =  bytes('{"msg":msg,"new layer":"""碰见一头老虎。'
                     'A:攻击'
                     'B：捕捉'
                     'C:逃跑'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/4')
def layer_4():
    if session.get('layer') != "3":
        return '你该去第三层闯关了'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "已击杀，虎皮，装备上血量加 40"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 40))
    elif q.lower() == "b":
        msg = "获得宠物老虎精Σ(っ °Д °;)っ,战斗力直线上升"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 20))
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 40))
    elif q.lower() == "c":
        msg = "你打不过大虫，内心自尊受挫，受到打击"
        ret.set_cookie('HP', str(int(request.cookies.get('fight')) - 20))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""碰见一位手上的老者：'
                        'A:上前帮助'
                        'B：漠不关心'
                        'C: 丢下药草，迅速离开'
                     '"""}'.encode("utf-8")))
    session['layer'] = "4"
    return ret

@app.route('/layer/5')
def layer_5():
    session['layer'] = '4'
    ret =  bytes('{"msg":msg,"new layer":"""碰见一位受伤的老者。'
                     'A:上前帮助'
                     'B：默默不问'
                     'C:递给他一些药，但是不想要惹是生非，转身离开'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/6')
def layer_6():
    if session.get('layer') != "4":
        return '你该去第四层闯关了'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "老者很感激，上前传授你绝世武功，战力上涨"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 40))
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 40))
    elif q.lower() == "b":
        msg = "无事发生，并且很伤老人的心💔💔💔"
    elif q.lower() == "c":
        msg = "老人还是感觉到你的好意，上前也丢下一串药草离开"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 35))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""你的面前是一排你大海：'
                        'A:相信自己，游过去🐂'
                        'B：偷渡'
                        'C: 老实一点，花些银子'
                     '"""}'.encode("utf-8")))
    session['layer'] = "5"
    return ret

@app.route('/layer/7')
def layer_7():
    session['layer'] = '5'
    ret =  bytes('{"msg":msg,"new layer":"""前面是一片大海，你要渡海。'
                     'A:相信自己的体力，游过去🐂'
                     'B：偷渡偷渡'
                     'C:老实一点，花谢银子还船票'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/8')
def layer_8():
    if session.get('layer') != "5":
        return '你该去第六层闯关了'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "体力不支，累死了（编不下去了😔）"
    elif q.lower() == "b":
        msg = "被官兵发现，乱棍打死（还有没有反转了呢，毕竟还没打BOSS呢(・∀・(・∀・(・∀・*)）"
    elif q.lower() == "c":
        msg = "来了一伙刀海盗，你勇敢上前对抗，但是被刺死"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 35))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""？？？：'
                        'A:？？？'
                        'B：？？？'
                        'C: ？？？'
                     '"""}'.encode("utf-8")))
    session['layer'] = "6"
    return ret

@app.route('/layer/9')
def layer_9():
    session['layer'] = '6'
    ret =  bytes('{"msg":msg,"new layer":"""重生'
                     'A:???'
                     'B：???'
                     'C:???'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/10')
def layer_10():
    if session.get('layer') != "6":
        return '你该去第七层闯关了'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "感动了海神，他令你复活，并获得了神祗"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 200))
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 200))
    elif q.lower() == "b":
        msg = "由于你偷渡被打死，转生成一头猪，但是不忘使命，仍要去击败魔王"
    elif q.lower() == "c":
        msg = "获得了正义之神的青睐，心灵得到了净化，肉体获得了提升"
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 200))
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 100))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""开始踏上征讨魔王的征程：'
                        'A:？？？'
                        'B：？？？'
                        'C: ？？？'
                     '"""}'.encode("utf-8")))
    session['layer'] = "7"
    return ret

@app.route('/layer/11')
def layer_11():
    session['layer'] = '7'
    ret =  bytes('{"msg":msg,"new layer":"""一路上见到了不同寻常的景色与趣闻'
                     'A:？？？'
                     'B：？？？'
                     'C:？？？'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/12')
def layer_12():
    if session.get('layer') != "7":
        return '你该去第八层闯关了'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "见证了干旱，于心不忍，施法降雨"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 50))
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 50))
    elif q.lower() == "b":
        msg = "出了猪圈，侥幸吃了人参果，身体变得更圆润了"
    elif q.lower() == "c":
        msg = "见证了人间的美好与苦难"
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 10))
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 10))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""马上接近魔王的城堡了，出现了三条岔路：'
                        'A:选择第一条路'
                        'B:选择第二条路'
                        'C: 选择第三条路'
                     '"""}'.encode("utf-8")))
    session['layer'] = "8"
    return ret

@app.route('/layer/13')
def layer_13():
    session['layer'] = '8'
    ret =  bytes('{"msg":msg,"new layer":"""马上接近魔王的城堡了，出现了三条岔路'
                     'A:选择第一条路'
                     'B:选择第二条路'
                     'C:选择第三条路'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/14')
def layer_14():
    if session.get('layer') != "8":
        return '你该去第九层闯关了'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "选择了第一条路，路上碰见了魔王的手下，打败了他们"
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 80))
    elif q.lower() == "b":
        msg = "选择了第二条路，一路畅通无阻"
    elif q.lower() == "c":
        msg = "选择了第三题条路，一路上坑坑洼洼，还好没有小兵阻挡"
        ret.set_cookie('HP', str(int(request.cookies.get("HP")) + 30))
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""到了城堡门口：'
                        'A:直接进去'
                        'B:扭扭捏捏'
                        'C:寻找帮手'
                     '"""}'.encode("utf-8")))
    session['layer'] = "9"
    return ret

@app.route('/layer/15')
def layer_15():
    session['layer'] = '8'
    ret =  bytes('{"msg":msg,"new layer":"""到了城堡门口'
                     'A:直接进去'
                     'B:扭扭捏捏'
                     'C:寻找帮手'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/16')
def layer_16():
    if session.get('layer') != "9":
        return '你要直接面对魔王了!!!!!'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "打败门卫，直捣黄龙"
        ret.set_cookie('fight', str(int(request.cookies.get("fight")) + 80))
    elif q.lower() == "b":
        msg = "小心翼翼，四处躲藏"
    elif q.lower() == "c":
        msg = "和伙伴一起冲进去"
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""打击魔王：'
                        'A:打击魔王！！！'
                        'B:打击魔王！！！'
                        'C:打击魔王！！！'
                     '"""}'.encode("utf-8")))
    session['layer'] = "10"
    return ret

@app.route('/layer/17')
def layer_17():
    session['layer'] = '9'
    ret =  bytes('{"msg":msg,"new layer":"""打击魔王'
                     'A:打击魔王！！！'
                     'B:打击魔王！！！'
                     'C:打击魔王！！！'
                     '"""}'.encode("utf-8"))
    return ret

@app.route('/layer/18')
def layer_18():
    if session.get('layer') != "10":
        return '打击魔王!!!!!'
    ret = make_response("")
    q = request.args.get("q")
    if q.lower() == 'a':
        msg = "你拥有海神的祝福，轻松打败了魔王，人间获得了和平，THE END"
    elif q.lower() == "b":
        msg = "你不小心滚到了魔王的脚下，魔王看见你要挑战他，竟然笑死了？！，你获得了猪猪侠^(*￣(oo)￣)^的美称, THE END"
    elif q.lower() == "c":
        msg = "你和你的伙伴打败了魔王，最后卸甲归田，享受人间美好"
    ret.data = bytes(msg.encode()) + bytes("\n".encode()) + (bytes('"new layer":"""THE END：'
                        'A:THE END'
                        'B:THE END'
                        'C:THE END'
                     '"""}'.encode("utf-8")))
    session['layer'] = "11"
    return ret

@app.route('/layer/19')
def layer_19():
    session['layer'] = '10'
    ret =  bytes('{"msg":msg,"new layer":"""世界美好'
                     'A:THE END!!!'
                     'B:THE END!!!'
                     'C:THE END!!!'
                     '"""}'.encode("utf-8"))
    return ret


if __name__ == '__main__':
    app.run()

